<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload=function(){
            var obj = {}
            var tarVal = 'hello'
            Object.defineProperty(obj,'age',{
                get(){
                    console.log("调用了get方法")
                    // return tarVal
                },
                set(newVal){
                    console.log("调用了set方法,设置的值为：",newVal)
                    tarVal = newVal
                    document.getElementById('inputA').value = tarVal
                    document.getElementById('b').innerHTML = tarVal
                }
            })
            // obj.age;
            // obj.age = 12
            document.addEventListener('keyup',function(e){
                console.log(e,e.target.value)
                obj.age = e.target.value
            })
        }
    </script>
</head>
<body>
    <input type="text" id="inputA">
    <span id="b"></span>
</body>
</html>
